home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / sockcmd.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  3KB  |  161 lines

  1. /* Socket status display code
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #ifdef MSDOS
  6. #include <dos.h>
  7. #endif
  8. #include "global.h"
  9. #include "config.h"
  10. #include "mbuf.h"
  11. #include "proc.h"
  12. #include "lzw.h"
  13. #include "usock.h"
  14. #include "socket.h"
  15. #include "ax25.h"
  16. #include "netrom.h"
  17. #include "tcp.h"
  18. #include "udp.h"
  19. #include "commands.h"
  20. #include "config.h"
  21.  
  22. /* Socket status display command */
  23. int
  24. dosock(argc,argv,p)
  25. int argc;
  26. char *argv[];
  27. void *p;
  28. {
  29.     register struct usock *up;
  30.     int s,i;
  31.     struct sockaddr fsock;
  32.     char *cp;
  33.  
  34.     if(argc < 2){
  35. #ifdef UNIX
  36.         tprintf("S#  Type    PCB  Remote socket         Owner\n");
  37. #else
  38.         tprintf("S#  Type    PCB  Remote socket         Owner\n");
  39. #endif
  40.         for(s=SOCKBASE;s<Nusock+SOCKBASE;s++){
  41.             up = itop(s);
  42.             if(up == NULLUSOCK)
  43.                 continue;
  44.  
  45.             i = sizeof(fsock);
  46.             if(getpeername(s,(char *)&fsock,&i) == 0 && i != 0)
  47.                 cp = psocket(&fsock);
  48.             else
  49.                 cp = "";
  50.  
  51. #ifdef UNIX
  52.             tprintf("%3d %-8s%8.8lx %-22s%8.8lx %-10s\n",
  53. #else
  54.             tprintf("%3d %-8s%4.4x %-22s%4.4x %-10s\n",
  55. #endif
  56.              s,Socktypes[up->type],FP_SEG(up->cb.p),cp,
  57.              FP_SEG(up->owner),up->owner->name);
  58.         }
  59.         return 0;
  60.     }
  61.     s = atoi(argv[1]);
  62.     if(s < SOCKBASE || s >= Nusock+SOCKBASE){
  63.         tprintf("Number out of range\n");
  64.         return 1;
  65.     }
  66.     up = itop(s);
  67.     if(up == NULLUSOCK){
  68.         tprintf("Socket not in use\n");
  69.         return 0;
  70.     }
  71. #ifdef UNIX
  72.     tprintf("%s %8.8lx %s",Socktypes[up->type],FP_SEG(up->cb.p),
  73. #else
  74.     tprintf("%s %4.4x %s",Socktypes[up->type],FP_SEG(up->cb.p),
  75. #endif
  76.      up->flag == SOCK_ASCII ? "ascii" : "binary");
  77.     if(up->eol[0] != '\0'){
  78.         tprintf(" eol seq:");
  79.         for(i=0;up->eol[i] != '\0' && i<sizeof(up->eol);i++)
  80.             tprintf(" %02x",up->eol[i]);
  81.     }
  82.     tprintf("  Since: %s",ctime(&up->created));
  83.     if(up->cb.p == NULL)
  84.         return 0;
  85.     switch(up->type){
  86.     case TYPE_RAW:
  87.     case TYPE_LOCAL_DGRAM:
  88.         tprintf("Inqlen: %d packets\n",socklen(s,0));
  89.         tprintf("Outqlen: %d packets\n",socklen(s,1));
  90.         break;
  91.     case TYPE_LOCAL_STREAM:
  92.         tprintf("Inqlen: %d bytes\n",socklen(s,0));
  93.         tprintf("Outqlen: %d bytes\n",socklen(s,1));
  94.         break;
  95.     case TYPE_TCP:
  96.         st_tcp(up->cb.tcb);
  97.         break;
  98.     case TYPE_UDP:
  99.         st_udp(up->cb.udp,0);
  100.         break;
  101. #ifdef    AX25
  102.     case TYPE_AX25I:
  103.         st_ax25(up->cb.ax25);
  104.         break;
  105. #endif
  106. #ifdef    NETROM
  107.     case TYPE_NETROML4:
  108.         donrdump(up->cb.nr4);
  109.         break;
  110. #endif
  111.     }
  112. #ifdef LZW
  113.     if(up->zout != NULLLZW)
  114.         tprintf("Compressed %ld bytes.\n",up->zout->cnt);
  115.     if(up->zin != NULLLZW)
  116.         tprintf("Decompressed %ld bytes.\n",up->zin->cnt);
  117. #endif
  118.     return 0;
  119. }
  120.  
  121. /* Kick the session related to a particular socket
  122.  * this is easier then the tcp kick, ax25 kick, etc... commands
  123.  * 920117 - WG7J
  124.  */
  125. int
  126. dokicksocket(argc,argv,p)
  127. int argc;
  128. char *argv[];
  129. void *p;
  130. {
  131.     register struct usock *up;
  132.     int s;  /*socket to kick*/
  133.     int retval=0;
  134.  
  135.     s = atoi(argv[1]);
  136.     if(s < SOCKBASE || s >= Nusock+SOCKBASE){
  137.         tputs("Number out of range\n");
  138.         return 1;
  139.     }
  140.     up = itop(s);
  141.     if(up == NULLUSOCK){
  142.         tputs("Socket not in use\n");
  143.         return 0;
  144.     }
  145.     if(up->type == TYPE_TCP)
  146.         retval = kick_tcp(up->cb.tcb);
  147. #ifdef AX25
  148.     if(up->type == TYPE_AX25I)
  149.         retval = kick_ax25(up->cb.ax25);
  150. #endif
  151. #ifdef NETROM
  152.     if(up->type == TYPE_NETROML4)
  153.         retval = kick_nr4(up->cb.nr4);
  154. #endif
  155.     if(retval == -1)
  156.         tputs("Kick not successfull\n");
  157.     return 0;
  158. }
  159.  
  160.  
  161.